# 使用 cmake -P main.cmake 执行对应.cmake文件
cmake_minimum_required(VERSION 3.20)

# 遍历范围
foreach(item RANGE 5)
    message("item is " ${item})
endforeach()

message("---------------------------")
# 遍历范围+步长
foreach(item RANGE 1 10 2)
    message("item is " ${item})
endforeach()

message("---------------------------")
# IN LISTS 遍历list
set(list 1 2 3)
foreach(item IN LISTS list)
    message("item is " ${item})
endforeach()

message("---------------------------")
# N LISTS = ITEMS，遍历list+添加元素
set(list 1 2 3)
foreach(item IN LISTS list ITEMS 5 6)
    message("item is " ${item})
endforeach()

message("---------------------------")
# ZIP_LISTS，遍历两个list
set(list 1 2 3)
set(arr one two three)
foreach(item IN ZIP_LISTS list arr)
    message("item_0 is " ${item_0} " item_1 is " ${item_1})
endforeach()

message("---------------------------")
# 5. 提前跳出 / 跳过
foreach(k RANGE 1 5)
    if(k EQUAL 3)
        continue() # 跳过 3
    endif()
    if(k EQUAL 4)
        break() # 到 4 就结束
    endif()
    message(STATUS "k = ${k}")
endforeach()
